package com.lsp.server.product.controller;

import com.lsp.server.common.Apiresponse;
import com.lsp.server.product.domain.po.ProductBrand;
import com.lsp.server.product.service.BrandService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ProductBrand
 * @Description 品牌管理
 * @Author Mr Hao
 * @Date 2021/11/25 16:08
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 查询品牌数据
     * @return
     */
    @PostMapping("/list")
    public Apiresponse getBrand(){
        return Apiresponse.success(brandService.getBrand());
    }

    /**
     * 新增品牌
     * @param form
     * @return
     */
    @PostMapping("/addBrand")
    public Apiresponse addBrand(ProductBrand form){
        try {
           if (null == form.getName()){
                return Apiresponse.Error(400,"参数错误");
           }
            brandService.addBrand(form);
            return Apiresponse.success("新增成功");
        }catch (Exception e){
            return Apiresponse.Error(500,"添加失败");
        }
    }
}
